package com.lc.soft.controller;

import com.lc.soft.entity.CommonParameter;
import com.lc.soft.entity.OrganizationEntity;
import com.lc.soft.service.IOrganizationService;
import com.lc.soft.utils.ResponseResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("organization")
@Log4j2
public class OrganizationController {

    private IOrganizationService organizationService;

    @Autowired
    public OrganizationController(IOrganizationService organizationService) {
        this.organizationService = organizationService;
    }

    @RequestMapping("create")
    public ResponseResult create(OrganizationEntity organizationEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = organizationService.create(organizationEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("update")
    public ResponseResult updateMap(OrganizationEntity organizationEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = organizationService.update(organizationEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("updateState")
    public ResponseResult updateState(OrganizationEntity organizationEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = organizationService.updateState(organizationEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("findOrganizationListByCondition")
    public ResponseResult findOrganizationListByCondition(CommonParameter commonParameter) {
        Long start = new Date().getTime();
        ResponseResult responseResult = organizationService.findOrganizationListByCondition(commonParameter);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("findPagedOrganizationListByCondition")
    public ResponseResult findPagedOrganizationListByCondition(CommonParameter commonParameter) {
        Long start = new Date().getTime();
        ResponseResult responseResult = organizationService.findPagedOrganizationListByCondition(commonParameter);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }
}
